package com.ews.onlineexchange.service;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;

import com.ews.onlineexchange.model.ServiceBuyer;
import com.ews.onlineexchange.model.ServiceSupplier;
import com.ews.onlineexchange.model.User;

@Named
@ConversationScoped
public class UserHome extends EntityHome<User, String> {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;
	
	private String oldEmail;


	public String getOldEmail() {
		return oldEmail;
	}

	public void setOldEmail(String oldEmail) {
		this.oldEmail = oldEmail;
	}

	@Override
	public User loadInstance() {
		User instance = super.loadInstance();
		this.setOldEmail(instance.getEmail());
		return instance;
	}

	public String editUsername(){
		User user = getInstance();
		saveAndFlush();
		if(user instanceof ServiceBuyer) return "ServiceBuyerList.xhtml?faces-redirect=true";
		else if(user instanceof ServiceSupplier) return "ServiceSupplierList.xhtml?faces-redirect=true";

		else return "";
	}
}
